package com.itheima.pinda.controller;

import com.itheima.pinda.DTO.transportline.TransportTripsDto;
import com.itheima.pinda.DTO.transportline.TransportTripsTruckDriverDto;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdTransportTripsService;
import com.itheima.pinda.service.PdTransportTripsTruckDriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车次信息管理")
@RestController
@RequestMapping(value = "/base/trips")
public class PdTransportTripsController {

    @Autowired
    private PdTransportTripsService transportTripsService;
    @Autowired
    private PdTransportTripsTruckDriverService transportTripsTruckDriverService;


    @ApiOperation(value = "车次信息新增")
    @PostMapping(value = "/insert")
    public TransportTripsDto insert(TransportTripsDto transportTripsDto){

        return transportTripsService.insert(transportTripsDto);
    }

    @ApiOperation(value = "车次信息更新")
    @PostMapping(value = "/update")
    public TransportTripsDto update(TransportTripsDto transportTripsDto){

        return transportTripsService.insert(transportTripsDto);
    }

    @ApiOperation(value = "根据id获取详情")
    @GetMapping(value = "/id")
    public TransportTripsDto selectById(@RequestParam("id") String id){
        return transportTripsService.selectById(id);
    }

    @ApiOperation(value = "获取车次列表")
    @PostMapping(value = "/findAll")
    public List<TransportTripsDto> findAll(@RequestParam(value = "transportLineId",required = false) String transportLineId,
                                           @RequestParam(value = "ids",required = false)List<String> ids){
        return transportTripsService.findAll(transportLineId,ids);
    }

    @ApiOperation(value = "删除车次信息")
    @DeleteMapping(value = "/delete")
    public Result delete(@RequestBody List<String> ids){

        transportTripsService.delete(ids);
        return Result.ok("删除成功！");
    }

    @ApiOperation(value = "批量保存车次与车辆和司机关系")
    @PostMapping(value = "/batchSave")
    public Result batchSave(@RequestBody List<TransportTripsTruckDriverDto> dtoList){
        transportTripsTruckDriverService.batchSave(dtoList);
        return Result.ok("新增成功！");
    }

    @ApiOperation(value = "查询车次与车辆和司机关系列表")
    @PostMapping(value = "/findAllT")
    public List<TransportTripsTruckDriverDto> findAllT(@RequestParam(value = "transportTripsId",required = false)String transportTripsId,
                                                      @RequestParam(value = "truckId",required = false)String truckId,
                                                      @RequestParam(value = "userId",required = false)String userId){

       return transportTripsTruckDriverService.findAll(transportTripsId,truckId,userId);
    }

}
